package com.qfedu.openplateform.gateway.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 *  ApplicationContextAware  接口成为注入接口
 *      作用就是在生成bean 会回调该接口 的方法  setApplicationContext 方法
 *       将容器的引用applicationContext  传递过来
 *
 * @author lileijian
 * @create 2021-12-05 0:46
 */
@Component
public class ApplicationContextHolder implements ApplicationContextAware {


    public static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

        // 让一个静态变量持有 容器上下文对象
        ApplicationContextHolder.applicationContext = applicationContext;
    }

    /**
     * 获取容器上下文
     * @return
     */
    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }
}
